# COMPSCI 389: Setting up Python Notebooks and Visual Studio Code Course notes and assignments will use Jupyter notebooks (previously called iPython notebooks), which are `.ipynb`. Jupyter notebooks let you mix code, text, math, and plots all in one place. They also allow you to easily execute blocks of code step-by-step. You can use any IDE you like (or Google Colab), but we recommend using Visual Studio Code (VSCode). VSCode is a popular choice for Python coding and is available for free for macOS, Windows, and Linux. The following instructions will focus on how to install Python and get you started with using Python notebooks in VSCode on Windows or macOS. ### Step 1 [For Windows users] Install Python 1. You can check if Python is already installed and the installed version by running this command in the Command Prompt: ```bash python3 --version ``` 2. We will be testing our code on Python versions 3.10 and 3.11, and recommend using **Python version 3.10 or newer.** You can use older versions, but we do not guarantee that the code we provide will run. Note that you can install multiple versions of python on your computer, and can select between them within VSCode. If you aren't using Python for anything else, you can also uninstall the old version of python (via the settings panel found by typing "Add or remove programs" in the start menu) and install a newer version. 3. If you haven't had Python installed yet or need a newer version, download Python from the official website: https://www.python.org/downloads/. 4. Run the installer. Ensure to **check the box "Add python.exe to PATH"** at the bottom of the installation window. This step is crucial. If you run into issues when using Python with VSCode, it may be because VSCode can't find the Python executable. This can be fixed by manually adding the path to python to your PATH environment variable [[link](https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows)], or by simply uninstalling Python and reinstalling it, ensuring that you check this box. ### Step 1 [For macOS users] Update Python 1. Python 3 should be pre-installed on macOS. You can check the installed version by running this command in the Terminal: ``` bash python3 --version ``` 2. We recommend using **Python version 3.10 or newer.** If you need to update your Python version, you can do this easily with Homebrew, a package manager for macOS. * First, ensure that Homebrew is installed. Use this command in the Terminal: ``` bash brew --version ``` * You can also update Homebrew to the latest version: ``` bash brew update ``` * If Homebrew is not installed, you'll see an error message indicating that the command was not found. To install Homebrew, use this command and follow the prompts (you can check the instructions and copy the installation link here: https://brew.sh/): ``` bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` * To upgrade Python to the latest version, use: ``` bash brew upgrade python ``` ### Step 2. Set up VSCode and Python notebooks 1. Download VSCode from the official website: [https://code.visualstudio.com/](https://code.visualstudio.com/). 2. You can try creating an empty `.ipynb` file on your computer and dragging it to the VSCode window. VSCode should then guide you through installing all the extensions you need to work with `.ipynb` files. 3. Alternatively, you can install the necessary extensions directly: * Python Extension: Open VSCode and install the Microsoft Python extension (`ms-python.python`) by searching for "Python" in the Extensions view (`Ctrl+Shift+X` or `Cmd+Shift+X`). * Jupyter Extension: Similarly, install the Microsoft Jupyter extension (`ms-toolsai.jupyter`) by searching for "Jupyter" in the Extensions view. 4. Check if everything is configured correctly by typing a simple Python command (e.g., `print("Hello, World")`), making sure the cell is a Python cell, and running the cell. ### Step 3. Install Python packages using pip 1. If you're familiar with virtual environments, we recommend you use them, but it's not required for the course. You can look into using conda for managing your Python environments (especially if you're on macOS): https://conda.io/projects/conda/en/latest/user-guide/install/index.html. 2. The homework assignments will list all the packages you need. As a start, the course notes rely on the following packages (and perhaps others as the course progresses): `pandas`, `numpy`, `matplotlib`, `scikit-learn`, and `seaborn`. 3. To install a package, open the Command Prompt or Terminal (you can open it on your computer or in VSCode by going to "Terminal" > "New Terminal") and use the `pip3` command followed by the name of the package. For example, to install `pandas`, run: ``` bash pip3 install pandas ```